import tornado.web
# 执行异步库
import peewee_async
import os
# 导服务器
from tornado import httpserver,ioloop
# 导入基础类
from base import BaseHandler
# 导入数据库操作类
from db import database
# 导入用户视图
from view.user_view import TestHandler



# 设置静态资源
static_path = os.path.join(os.path.dirname(__file__),"static")


# 执行tornado
# 执行方法
def main():
    # 实例化tornado对象
    app = tornado.web.Application(
        handlers = [
            (r'/test/',TestHandler),
            

        ],static_path=static_path,debug=False
    )

    # 将异步数据注入tornado
    app.objects = peewee_async.Manager(database)


    # 声明服务器
    server = httpserver.HTTPServer(app,xheaders = True,)
    # 指定端口号
    server.listen(8000)
    # server.listen(443)
    # 执行事件循环 ioloop
    tornado.ioloop.IOLoop.instance().start()

if __name__ == '__main__':

    print("服务已开启...")
    main()